<?php
include 'db.php';

$username=$_GET['u'];
//echo "$username".PHP_EOL;
$q=mysql_query("SELECT sessionid, tutor, student, subject FROM sessions WHERE (student='{$username}' OR tutor='{$username}') AND (tutortime > (NOW() -5) OR studenttime > (NOW() -5))");

while($data = mysql_fetch_row($q))
	if($username == $data[1]){
	    echo "$data[0]".PHP_EOL;
	    echo "$data[2]".PHP_EOL;
	    echo "$data[3]".PHP_EOL;
	    echo "tutor".PHP_EOL;
	    }
	else if($username == $data[2]){
	    	    echo "$data[0]".PHP_EOL;
        	    echo "$data[1]".PHP_EOL;
        	    echo "$data[3]".PHP_EOL;
        	    echo "student".PHP_EOL;
	    }
mysql_close($link);
?>
